package com.mnsq.user.bean.dto;

import com.mnsq.common.bean.enums.RegisterType;
import com.mnsq.common.tools.tool.TimeUtils;
import com.mnsq.user.bean.entity.Account;
import com.mnsq.user.bean.entity.User;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * @author Administrator
 * @date 2019/3/21 0021
 */
@Data
@Accessors(chain = true)
public class LoginInfo implements Serializable {

    private Long userId;
    private String token;
    private String userAccount;
    private String petName;
    private Long roleId;
    private String headPicSmall;
    private String headPicMiddle;
    private String headPicLarge;
    private String registerTime;
    private String userUnique;
    /**
     * 使用RegisterType枚举，当前登录类型
     */
    private Integer type;
    private String typeStr;
    /**
     * 职业
     */
    private String vocation;
    /**
     * 个性签名，个人介绍
     */
    private String signature;

    private LoginInfo() {
    }

    public static LoginInfo getInstance() {
        return new LoginInfo();
    }

    public LoginInfo setInfo(Account account) {
        this.userAccount = account.getUserName().substring(0, 1) + "**" + account.getUserName().substring(account.getUserName().length() - 1);
        this.type = Integer.valueOf(account.getType() == null ? "10" : account.getType());
        this.typeStr = RegisterType.getName(this.type);
        this.userId = account.getUserId();
        this.registerTime = TimeUtils.transformDateToString(account.getCreateTime(), TimeUtils.TimeTypeEnum.TIME_TO_SECOND_SPACE);
        return this;
    }

    public LoginInfo setInfo(User user) {
        this.petName = user.getPetName();
        this.headPicLarge = user.getHeadOriginalPic();
        this.headPicMiddle = user.getMiddlePic();
        this.headPicSmall = user.getSmallPic();
        this.signature = user.getSelfDescription();
        this.vocation = user.getVocation();
        this.userUnique = user.getUnique();
        this.roleId = user.getRoleId();
        return this;
    }
}
